<template>
  <view class="su-sort-tab">
    <view class="su-sort-tab-item" :class="{active:value===item[defaultProps.value]}" v-for="(item,index) in list"
      :key="index" @click="sortTabItemClick(item)">
      {{item[defaultProps.label]}}
    </view>
  </view>
</template>

<script>
  export default {
    name: "su-sort-tab",
    model: {
      prop: 'value',
      event: 'change'
    },
    props: {
      value: {
        type: [Number, String],
        default: ''
      },
      // 是否开启底部安全区适配
      list: {
        type: Array,
        default () {
          return []
        }
      },
      defaultProps: {
        type: Object,
        default () {
          return {
            value: 'value',
            label: 'label'
          }
        }
      }
    },
    data() {
      return {
        sortTabItemClick(item) {
          this.$emit('change', item[this.defaultProps.value])
        }
      };
    }
  }
</script>

<style lang="scss">
  .su-sort-tab {
    display: flex;
    height: 88upx;
    align-items: center;

    &-item {
      margin-right: 60upx;
      font-size: 14px;
      color: #666666;
      transition: all 0.3s;

      &.active {
        color: #2A333B;
        font-weight: bold;
      }
    }
  }
</style>
